//
//  MQUserAccount.swift
//  SinaWeiBo
//
//  Created by 毛强 on 16/1/18.
//  Copyright © 2016年 itheima. All rights reserved.
//

import UIKit

class MQUserAccount: NSObject, NSCoding {
    
    var avatar_lager:String?
    var screen_name:String?
    var uid:String?
    var expires_in:NSTimeInterval = 0 {
        didSet{
            expiresDate = NSDate().dateByAddingTimeInterval(expires_in)
        }
    }
    
    var expiresDate:NSDate?
    var access_token:String?
    var remind_in:String?
    
    init(dict: [String : AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {}
    
    
    // MARK: - 归档
    func encodeWithCoder(aCoder: NSCoder) {
        aCoder.encodeObject(avatar_lager, forKey: "avatar_lager")
        aCoder.encodeObject(screen_name, forKey: "screen_name")
        aCoder.encodeObject(uid, forKey: "uid")
        aCoder.encodeObject(expiresDate, forKey: "expiresDate")
        aCoder.encodeObject(access_token, forKey: "access_token")
        aCoder.encodeObject(remind_in, forKey: "remind_in")

    }
    
    required init?(coder aDecoder: NSCoder) {
        avatar_lager = aDecoder.decodeObjectForKey("avatar_lager") as? String
        screen_name = aDecoder.decodeObjectForKey("screen_name") as? String
        uid = aDecoder.decodeObjectForKey("uid") as? String
        expiresDate = aDecoder.decodeObjectForKey("expiresDate") as? NSDate
        access_token = aDecoder.decodeObjectForKey("access_token") as? String
        remind_in = aDecoder.decodeObjectForKey("remind_in") as? String

    }
    // MARK: - 解档
    override var description: String{
        let key = ["uid", "expires_in", "access_token", "remind_in", "avatar_lager", "screen_name"]
        return dictionaryWithValuesForKeys(key).description
    }
}
